print("梅登海格计算工具")
print("请依次输入所求地点经纬度")
print("东经为正，西经为负：")
X = float(input("所求地点经度： "))

Y = float(input("所求地点纬度： "))

Z = int(input("请输入精度，大于等于2小于等于4： "))
import math as mt
if X >= 180 or X < -180 or Y >= 90 or Y < -90 or Z < 2 or Z > 4:
    print("输入错误")
    exit()
else:
    print("Maidenhead is :")
    cal1 = X/20 + 9
    cal2 = Y/10 + 9
    cal3 = int(cal1)
    cal4 = int(cal2)
    print("%c %c "%((cal3 + 65),(cal4 + 65)),end='')
    i = 1
    while Z > i:
        i = i + 1
        if i % 2 == 0:
            cal1 = (cal1 - cal3) * 10
            cal2 = (cal2 - cal4) * 10
            cal3 = int(cal1)
            cal4 = int(cal2)
            print("%d %d "%(cal3,cal4),end='')
        else:
            cal1 = (cal1 - cal3) * 24
            cal2 = (cal2 - cal4) * 24
            cal3 = int(cal1)
            cal4 = int(cal2)
            print("%c %c "%((cal3+97),(cal4+97)),end='')